const express = require('express');
const config = require('../config');

// 创建路由实例
const router = express.Router();

/**
 * 路由配置
 */

// 导入API路由
const apiRoutes = require('./api');

// 健康检查路由
router.get('/health', (req, res) => {
  res.status(200).json({
    success: true,
    message: '服务运行正常',
    timestamp: new Date().toISOString(),
    environment: config.app.environment,
    version: '1.0.0'
  });
});

// API根路由
router.get('/api', (req, res) => {
  res.status(200).json({
    success: true,
    message: 'Harmony API 服务',
    version: 'v1',
    endpoints: {
      health: '/health',
      api: '/api/v1',
      docs: '/api/docs'
    }
  });
});

// 挂载API版本路由
router.use(config.app.apiPrefix, apiRoutes);

// 导出路由
module.exports = router;

/**
 * 路由配置函数
 * @param {Object} app - Express应用实例
 */
module.exports.setupRoutes = (app) => {
  // 挂载路由
  app.use('/', router);
  
  console.log('路由系统配置完成');
};